package com.masterclient.app.businessmodule.vipmodule.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.alibaba.android.arouter.launcher.ARouter;
import com.eoner.managerlibrary.router.AroutePath;
import com.masterclient.app.R;
import com.masterclient.app.base.FragmentHostActivity;
import com.masterclient.app.businessmodule.vipmodule.bean.ServiceOrder;
import com.masterclient.app.businessmodule.vipmodule.card.IBaseCard;
import com.masterclient.app.businessmodule.vipmodule.card.OrderServiceCard;
import java.util.ArrayList;
import java.util.List;


/**
 * 售后订单adapter
 */
public class ServiceOrderAdapter extends RecyclerView.Adapter<IBaseCard> {

    private Context mContext;
    private List<ServiceOrder> orderList;

    public ServiceOrderAdapter(Context ctx) {
        this.mContext = ctx;
        orderList = new ArrayList<>();
    }

    public void setOrderList(List<ServiceOrder> orderList) {
        if(orderList != null){
            int start = this.orderList.size();
            this.orderList.addAll(orderList);
            notifyItemRangeChanged(start,orderList.size());
        }

    }

    public void setNewData(List<ServiceOrder> orderList) {
        this.orderList = orderList;
        notifyDataSetChanged();
    }

    @Override
    public IBaseCard onCreateViewHolder(ViewGroup parent, int viewType) {
        return new OrderServiceCard(LayoutInflater.from(mContext).inflate(R.layout.card_service_order, parent, false), mContext);
    }

    @Override
    public void onBindViewHolder(final IBaseCard holder, final int position) {
        holder.onBindViewHolder(orderList.get(position), position);
        String refund_no = orderList.get(position).getRefund_no();
        String title = orderList.get(position).getRefund_status_desc();
        holder.itemView.setOnClickListener(v -> {
            Fragment fragment = (Fragment) ARouter.getInstance().build(AroutePath.REFUND_DETAILS_FRAGMENT)
                    .withString("order_id","")
                    .withString("refundNo",refund_no)
                    .navigation();
            FragmentHostActivity.openFragment(mContext, fragment);
//            FragmentHostActivity.openFragment(mContext, fragment);
//            Intent intent = new Intent(mContext, ServiceOrderDetailActivity.class);
//            intent.putExtra("refund_no", refund_no);
//            intent.putExtra("title", title);
//            mContext.startActivity(intent);
        });
    }

    @Override
    public int getItemCount() {
        return null == orderList ? 0 : orderList.size();
    }

}
